home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / comp / iccomp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  14.4 KB  |  391 lines

  1. /*
  2.         Symboltable structure:
  3.  
  4.  
  5.         After a functions is defined, the field
  6.  
  7.             funtab.symbol[index_of_the_function].var.vu.i->count
  8.  
  9.         contains the offset of the 1st byte of the function in the s_bin file.
  10.  
  11.  
  12.     Adding a hidden (macro) function:
  13.     =================================
  14.  
  15.     ../RSS/ICRSS.H:
  16.         1.  add a f_... functionname before the f_hlt entry in the FUNNR enum.
  17.     PARSER:
  18.         1.  define a parser constant, to be returned by the lexer
  19.         2.  expand the proper nonterminal activated in the 'function'
  20.             nonterminal, to recognize the new parser constant
  21.         3.  adapt the corresponding C function to recognize the new f_-entry.
  22.             This function should call 'callhidden()'
  23.     LEXER:
  24.         1.  add the name of the function to the set of keywords, return the
  25.             newly defined parser constant, set the yylval.type field to the
  26.             newly defined f_-value.
  27.     DATA.C:
  28.         1.  add the definition of the function to hidden[]
  29.         2.  add the name of the function to funstring[]
  30.     ICCOMP.H (this file):
  31.         1.  add an entry he_... to the HIDDEN_ENUM enum, before the final he_
  32.             entry
  33.     touch
  34.             CLEARHID.C and YYLEXHID.C
  35.     adapt
  36.             DOC/ICMAKE.1, copy this file to \sys\man, and update
  37.             \sys\man\icmake.1
  38.     remake
  39.             icm-comp.
  40.  
  41. */
  42.  
  43. #include "../rss/icrssdef.h"
  44.  
  45. #ifdef MSDOS
  46. #define __STDC__
  47. #endif
  48.  
  49.  
  50. #ifndef MSDOS
  51. #include <memory.h>
  52. #define bcopy(s,d,l)    memcpy((d),(s),(l))
  53. #endif
  54.  
  55. typedef enum                                /* order of elements must follow */
  56. {                                           /* definition of hidden[] in     */
  57.     he_older = 0,                           /* data.c                        */
  58.     he_younger = 1,                         /* reserved values 0 and 1 */
  59.     he_strlwr,                              /* strlwr macro */
  60.     he_strupr,                              /* strupr macro */
  61.     he_strlen,                              /* strlen macro */
  62.     he_substr,                              /* substr macro */
  63.  
  64.     he_,                                    /* must be last ! */
  65. } HIDDEN_ENUM_;
  66.  
  67. typedef enum
  68. {
  69.     pre_op,
  70.     post_op,
  71. } PREPOST_;
  72.  
  73. typedef enum
  74. {
  75.     j_uncond,                               /* unconditional jump */
  76.     j_truelist,                             /* jump batchpatch for truelist */
  77.     j_falselist,                            /* jump backbatch for falselist */
  78. } JMP_COND_;
  79.  
  80. #define down_type(e,v)          ((e)->type &= ~(v))
  81. #define test_type(e,v)          ((e)->type &   (v))
  82. #define set_type(e,v)           ((e)->type =   (v))
  83. #define up_type(e,v)            ((e)->type |=  (v))
  84.  
  85. #define ALLTYPES                (e_int | e_list | e_str | e_bool)
  86.  
  87. #define codestruc(estruc, x)    (&(((ESTRUC_ *)((estruc)->code))[x]))
  88.  
  89. typedef struct
  90. {
  91.     unsigned
  92.         index;                              /* index in stringsection */
  93.     char
  94.         *string;                            /* string itself */
  95. } STRINGTAB_;
  96.  
  97. typedef struct                              /* symtab used with the compiler */
  98. {
  99.     VAR_
  100.         var;
  101.     char
  102.         *name;
  103. } SYMBOL_;
  104.  
  105. typedef struct
  106. {
  107.     unsigned
  108.         n_allocated,                        /* available memory */
  109.         n_defined;                          /* defined variables */
  110.     SYMBOL_
  111.         *symbol;
  112. } SYMTAB_;
  113.  
  114. typedef struct
  115. {
  116.     E_TYPE_
  117.         type;                               /* type of the expression */
  118.     unsigned
  119.         truelen,
  120.         falselen,
  121.         codelen,                            /* length of the code */
  122.         evalue,                             /* index or value of the expression */
  123.         *truelist,
  124.         *falselist;
  125.     INT8
  126.         *code;
  127. } ESTRUC_;
  128.  
  129. typedef struct
  130. {
  131.     char
  132.         *name,                              /* name of the hidden fun */
  133.         *source;                            /* source of the hidden function */
  134.     unsigned
  135.         type,                               /* returntype */
  136.         this,                               /* set to 1 if called */
  137.         nargs;                              /* # of arguments */
  138. } HIDDEN_FUNCTION_;
  139.  
  140. #define YYSTYPE ESTRUC_
  141.  
  142. /*
  143.                              B I F L E X
  144.  
  145.     Prototypes of often used functions and variabels defined in code
  146.     generated by FLEX and BISON.
  147.  
  148. */
  149.  
  150. #ifndef YYSTYPE
  151.     #define YYSTYPE int
  152. #endif
  153.  
  154. extern YYSTYPE
  155.     yylval;                                 /* yyparse() semantic value */
  156.  
  157. extern FILE
  158.     *yyin,                                  /* yylex() input file */
  159.     *yyout;                                 /* yylex() output file */
  160.  
  161. extern int
  162.     yy_init,                                /* yylex() initializer: 1 to init. */
  163.     yyleng,                                 /* strlen(yytext) */
  164.     yynerr;                                 /* number of parse errors so far */
  165.  
  166. extern unsigned
  167.     yylineno;                               /* yylex() line counter */
  168.  
  169. extern char
  170.     *yytext;                                /* yylex() read input chars */
  171.  
  172. extern int
  173.     parse_error,
  174.     (*yylex_input)(char *, int);            /* pointer to yylex input to use */
  175.  
  176. int yyerror(char *);                        /* yyparse() error function */
  177. int yylex(void);                            /* yylex() */
  178. int yyparse(void);                          /* yyparse() */
  179.  
  180. /*
  181.                                B I F L E X
  182.  
  183.                             E N D S    H E R E
  184. */
  185.  
  186. typedef enum
  187. {
  188.     err_openpar_expected,
  189.     err_closepar_expected,
  190.     err_openbrace_expected,
  191.     err_closebrace_expected,
  192.     err_semicol_expected,
  193.     err_assign_expected,
  194.     err_in_expression,
  195.     err_comma_expected,
  196.     err_statements_expected,
  197.     err_identifier_expected,
  198.     err_code_or_vars_expected,
  199.     err_comma_or_closepar_expected,
  200.     err_number_expected,
  201.     err_older_younger,
  202. } PARSE_ERR_;
  203.  
  204. extern char
  205.     release[],
  206.     *filenames,
  207.     *funstring[],
  208.     icm_comp[],
  209.     illegal_argcount[],
  210.     illegal_cast[],
  211.     illegal_type[],
  212.     lvalue_needed[],
  213.     not_on_lists[],
  214.     not_on_strings[],
  215.     nullstring[],
  216.     only_on_ints[],
  217.     *opstring[],
  218.     *source_name,
  219.     string[],
  220.     *stringbuf,
  221.     type_conflict[],
  222.     version[];
  223.  
  224. extern E_TYPE_
  225.     vartype;
  226.  
  227. extern E_TYPE_
  228.     optype[];
  229.  
  230.  
  231. extern FILE
  232.     *s_bin;
  233.  
  234. extern OPCODE_
  235.     lastop;
  236.  
  237. extern STRINGTAB_
  238.     *stringtab;
  239.  
  240. extern SYMTAB_
  241.     funtab,
  242.     local,
  243.     global,
  244.     *entertab;
  245.  
  246. extern HIDDEN_FUNCTION_
  247.     hidden[he_];
  248.  
  249. extern unsigned
  250.     break_ok,
  251.     *dead,
  252.     dead_sp,
  253.     errcount,
  254.     hidden_called,
  255.     nestlevel,
  256.     n_params,
  257.     n_strings,
  258.     sem_err,
  259.     stringsize,
  260.     yylineno;
  261.  
  262.  
  263. int conflict (ESTRUC_ *, ESTRUC_ *,     /* conflicting binary types */
  264.                   OPCODE_);
  265. int test_binop (OPCODE_, ESTRUC_ *,     /* test binop legality */
  266.                       ESTRUC_ *);
  267. int test_operand (ESTRUC_ *, OPCODE_); /* test legality of operand */
  268. int yylex_file(char *, int);                /* read yylex input from yyin */
  269. int yylex_hidden(char *, int);              /* read yylex input from buffer */
  270.  
  271. unsigned fetchfun (void);              /* fetch index of function */
  272. unsigned lookstring (char *);          /* look for string in stringtab */
  273. unsigned looksym (SYMTAB_ *);          /* look for symbol in symboltab */
  274. unsigned rm_jmp_zero (unsigned,         /* remove jmp 0 from || && lists */
  275.                  unsigned *, unsigned);
  276.  
  277. ESTRUC_ *addition (ESTRUC_ *, ESTRUC_ *);  /* + code */
  278. ESTRUC_ *and_boolean (ESTRUC_ *, ESTRUC_ *);/* && code */
  279. ESTRUC_ *assign  (ESTRUC_ *, ESTRUC_ *);   /*  = code (shell) */
  280. ESTRUC_ *assignment  (ESTRUC_ *, ESTRUC_ *, /*  = code */
  281.                                     char *);
  282. ESTRUC_ *band (ESTRUC_ *, ESTRUC_ *);           /* & (binary) code */
  283. ESTRUC_ *bnot (ESTRUC_ *);                      /* ~ code */
  284. ESTRUC_ *bor  (ESTRUC_ *, ESTRUC_ *);           /* | (binary) code */
  285. ESTRUC_ *break_stmnt (void);           /* process break stmnt */
  286. ESTRUC_ *callfun (unsigned, ESTRUC_ *);  /* call function */
  287. ESTRUC_ *cast (E_TYPE_, ESTRUC_ *);      /* perform cast */
  288. ESTRUC_ *catcode (ESTRUC_ *,              /* write info rval behind lval */
  289.                              ESTRUC_ *);
  290. ESTRUC_ *cat_expr (ESTRUC_ *,               /* ,-separated expressions */
  291.                              ESTRUC_ *);
  292. ESTRUC_ *cat_stmnt (ESTRUC_ *,              /* catenate/write stmnts */
  293.                              ESTRUC_ *);
  294. ESTRUC_ *divide (ESTRUC_ *, ESTRUC_ *);    /* / code */
  295. ESTRUC_ *equal (ESTRUC_ *, ESTRUC_ *);     /* == code */
  296. ESTRUC_ *exec_fprintf (E_TYPE_, ESTRUC_ *);/* exec() and fprintf() */
  297. ESTRUC_ *execute (ESTRUC_ *);              /* execute() (full arglist) */
  298. ESTRUC_ *expr_stmnt (ESTRUC_ *);           /* expr ; code */
  299. ESTRUC_ fetchvar (void);                   /* fetch variable */
  300. ESTRUC_ *firstarg (ESTRUC_ *);             /* (arg   code */
  301. ESTRUC_ *first_stmnt (ESTRUC_ *);          /* catenate/write stmnts */
  302. ESTRUC_ *for_stmnt (ESTRUC_ *, ESTRUC_ *,   /* for statement */
  303.                        ESTRUC_ *, ESTRUC_ *);
  304. ESTRUC_ *greater (ESTRUC_ *, ESTRUC_ *);   /* > code */
  305. ESTRUC_ *gr_equal (ESTRUC_ *, ESTRUC_ *);  /* >= code */
  306. ESTRUC_ *icast (ESTRUC_ *);                /* cast to int */
  307. ESTRUC_ *if_stmnt (ESTRUC_ *, ESTRUC_ *,    /* if code */
  308.                                ESTRUC_ *);
  309. ESTRUC_ *incdec (PREPOST_, OPCODE_,         /* E.g., c++ */
  310.                                ESTRUC_ *);
  311. ESTRUC_ *insertarg (ESTRUC_ *, ESTRUC_ *);/* arg1, before arg2, ... */
  312. ESTRUC_ *lcast (ESTRUC_ *);                /* cast to list */
  313. ESTRUC_ *makelist (ESTRUC_ *, E_TYPE_);         /* makelist() */
  314. ESTRUC_ *math_ass (ESTRUC_ *, ESTRUC_ *,    /* shell for math-asgnmt */
  315.                        ESTRUC_ *(*)(ESTRUC_ *, ESTRUC_ *),
  316.                        char *);
  317. ESTRUC_ *modulo (ESTRUC_ *, ESTRUC_ *);    /* % code */
  318. ESTRUC_ *multargs (ESTRUC_ *, ESTRUC_ *);  /* (arg1, arg2, ... code */
  319. ESTRUC_ *multiply (ESTRUC_ *, ESTRUC_ *);  /* * code */
  320. ESTRUC_ *negate (ESTRUC_ *);               /* - (unary) code */
  321. ESTRUC_ *not_boolean (ESTRUC_ *);          /* ! code */
  322. ESTRUC_ *old (ESTRUC_ *, ESTRUC_ *);       /* older code */
  323. ESTRUC_ *onearg (E_TYPE_, ESTRUC_ *);      /* fun(x)  code */
  324. ESTRUC_ *optint_special (E_TYPE_,           /* fun([int,] ...) */
  325.                       ESTRUC_ *, ESTRUC_ *);
  326. ESTRUC_ *optint_string (E_TYPE_,        /* chdir(), system() */
  327.                       ESTRUC_ *, ESTRUC_ *);
  328. ESTRUC_ *or_boolean (ESTRUC_ *, ESTRUC_ *);/* || code */
  329. ESTRUC_ *return_stmnt (E_TYPE_, ESTRUC_ *);/* exit(), return(); */
  330. ESTRUC_ *specials (E_TYPE_, ESTRUC_ *);    /* fun(x, y, ...)  code */
  331. ESTRUC_ *scast (ESTRUC_ *);                /* cast to str */
  332. ESTRUC_ *shl (ESTRUC_ *, ESTRUC_ *);            /* << (binary) code */
  333. ESTRUC_ *shr (ESTRUC_ *, ESTRUC_ *);            /* >> (binary) code */
  334. ESTRUC_ *smaller (ESTRUC_ *, ESTRUC_ *);   /* < code */
  335. ESTRUC_ *sm_equal (ESTRUC_ *, ESTRUC_ *);  /* <= code */
  336. ESTRUC_ stackframe (E_TYPE_);              /* initialize a stack-element */
  337. ESTRUC_ *subtract (ESTRUC_ *, ESTRUC_ *);  /* - (binary) code */
  338. ESTRUC_ *strupr_lwr (E_TYPE_, ESTRUC_ *);       /* strupr<->strlwr */
  339. ESTRUC_ *threeargs (ESTRUC_ *,              /* fun(x, y, z)  code */
  340.                         ESTRUC_ *, ESTRUC_ *);
  341. ESTRUC_ *twoargs (E_TYPE_, ESTRUC_ *,       /* fun(x, y)  code */
  342.                                ESTRUC_ *);
  343. ESTRUC_ *unequal (ESTRUC_ *, ESTRUC_ *);   /* != code */
  344. ESTRUC_ *while_stmnt (ESTRUC_ *, ESTRUC_ *);/* while code */
  345. ESTRUC_ *young (ESTRUC_ *, ESTRUC_ *);     /* younger code */
  346. ESTRUC_ *xor  (ESTRUC_ *, ESTRUC_ *);           /* ^ (binary) code */
  347. ESTRUC_ *zeroargs (E_TYPE_);               /* fun()  code */
  348.  
  349. void    addpatch (unsigned *, unsigned,     /* add value to patch-list */
  350.                                unsigned);
  351. void    backend (void);                /* finish s_bin construction */
  352. void    btoi (ESTRUC_ *);              /* boolean to int */
  353. void    callrss (ESTRUC_ *, FUNNR_      /* call rss function */
  354.                                 MARG);     /* and add asp, xxx instruction */
  355. void    callhidden(int, ESTRUC_ *);         /* call hidden function */
  356. void    catargs (ESTRUC_ *);           /* arguments to code */
  357. void    catstrings (ESTRUC_ *,          /* catenate string consts */
  358.                              ESTRUC_ *);
  359. void    change_file (char *);          /* switch to other file */
  360. void    clearbin (ESTRUC_ *,            /* clear and init 2 ESTRUC_s */
  361.                       ESTRUC_ *);
  362. void    clear_hidden(void);                 /* clear hidden function-names */
  363. void    close_fun (ESTRUC_ *);         /* close a function def. */
  364. void    copy_to_pop (ESTRUC_ *);       /* op_copy_var to op_pop_var */
  365. void    defcode (ESTRUC_ *, ESTRUC_ *,  /* generate default e_int|e_code */
  366.                   OPCODE_);
  367. void    discard (ESTRUC_ *);           /* free memory used by ESTRUC_ */
  368. void    etob (ESTRUC_ *);              /* expr. prepare for boolean */
  369. void    etoc (ESTRUC_ *);              /* convert E to code */
  370. void    enter (void);                  /* enter somthing in a symtab */
  371. void    entervar (void);               /* enter variable in l/g-tab */
  372. void    fetob (ESTRUC_ *);             /* forced e conversion to boolean */
  373. void    hidden_functions (void);            /* patchup/generate hidden funs */
  374. void    last_stmnt (ESTRUC_ *);        /* write last stmnt */
  375. void    make_frame (void);             /* generate op_frame */
  376. void    gencode (ESTRUC_ *, OPCODE_     /* append new code */
  377.                                    MARG);
  378. void    open_fun (void);               /* open a function */
  379. void    outbin (void *, unsigned);     /* write INT8s to s_bin */
  380. void    outcode (ESTRUC_ *, int,        /* append code to e->code */
  381.                         unsigned);
  382. void    patchfalse (ESTRUC_ *);        /* jmp_false target */
  383. void    patchtrue (ESTRUC_ *);         /* jmp_true target */
  384. void    patchup (INT8 *, unsigned,      /* patchup t/f list */
  385.                      unsigned *, unsigned, int);
  386. void    patchup_true (ESTRUC_ *, int); /* batchpatch truelist */
  387. void    patchup_false (ESTRUC_ *, int);/* batchpatch truelist */
  388. void    pop_dead(void);                     /* restore dead-level */
  389. void    push_dead(void);                    /* new dead-level */
  390. void    semantic (char * MARG);        /* give semantic error */
  391.